﻿using System;
using Xunit;

namespace Unity.String.Tests.Number
{
    public class GuidExtendTest
    {
        [Fact]
        public void MethodsTest()
        {
            GuidEx testGuidExValue = new GuidEx();

            char[] testEmptyCharArrayBuffer = Array.Empty<char>();
            
            bool returnTryFormatWithEmptyBufferResult = testGuidExValue.TryFormat(testEmptyCharArrayBuffer.AsSpan(), 
                out int testCharArrayBufferWithEmptyBufferWrittenFormatException);
            Assert.False(returnTryFormatWithEmptyBufferResult);
            Assert.Equal(0, testCharArrayBufferWithEmptyBufferWrittenFormatException);
            
            char[] testCharArrayBuffer = new char[1024];
            Assert.Throws<FormatException>(() =>
            { 
                testGuidExValue.TryFormat(testCharArrayBuffer.AsSpan(), 
                    out int _, "G");
            });

            Assert.Throws<FormatException>(() =>
            { 
                testGuidExValue.TryFormat(testCharArrayBuffer.AsSpan(), 
                    out int _, "GDP");
            });
            
            testGuidExValue.TryFormat(testCharArrayBuffer.AsSpan(), 
                out int testCharArrayBufferWrittenWithEmptyFormat, "");
            int needCharArrayBufferWrittenWithEmptyFormat = 36;
            Assert.Equal(needCharArrayBufferWrittenWithEmptyFormat, 
                testCharArrayBufferWrittenWithEmptyFormat);
            
            testGuidExValue.TryFormat(testCharArrayBuffer.AsSpan(), 
                out int testCharArrayBufferWrittenWithFormatD, "D");
            int needCharArrayBufferWrittenWithFormatD = 36;
            Assert.Equal(needCharArrayBufferWrittenWithFormatD, 
                testCharArrayBufferWrittenWithFormatD);
            
            testGuidExValue.TryFormat(testCharArrayBuffer.AsSpan(), 
                out int testCharArrayBufferWrittenWithFormatN, "N");
            int needCharArrayBufferWrittenWithFormatN = 32;
            Assert.Equal(needCharArrayBufferWrittenWithFormatN, 
                testCharArrayBufferWrittenWithFormatN);
            
            testGuidExValue.TryFormat(testCharArrayBuffer.AsSpan(), 
                out int testCharArrayBufferWrittenWithFormatB, "B");
            int needCharArrayBufferWrittenWithFormatB = 38;
            Assert.Equal(needCharArrayBufferWrittenWithFormatB, 
                testCharArrayBufferWrittenWithFormatB);
            
            testGuidExValue.TryFormat(testCharArrayBuffer.AsSpan(), 
                out int testCharArrayBufferWrittenWithFormatP, "P");
            int needCharArrayBufferWrittenWithFormatP = 38;
            Assert.Equal(needCharArrayBufferWrittenWithFormatP, 
                testCharArrayBufferWrittenWithFormatP);
            
            testGuidExValue.TryFormat(testCharArrayBuffer.AsSpan(), 
                out int testCharArrayBufferWrittenWithFormatX, "X");
            int needCharArrayBufferWrittenWithFormatX = 68;
            Assert.Equal(needCharArrayBufferWrittenWithFormatX, 
                testCharArrayBufferWrittenWithFormatX);
        }
    }
}